package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.Xdfeizhi;
import com.amsp.oa.oademo.service.XdfeizhiService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件修订/废止申请单管理")
@RestController
@RequestMapping("/api/xdfeizhi")
public class XdfeizhiController {

    @Autowired
    private XdfeizhiService xdfeizhiService;

    @ApiOperation("分页查询文件修订/废止申请单")
    @GetMapping("/page")
    public ResponseEntity<IPage<Xdfeizhi>> getXdfeizhiPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("搜索关键词") @RequestParam(required = false) String keyword) {
        return ResponseEntity.ok(xdfeizhiService.getXdfeizhiPage(pageNum, pageSize, keyword));
    }

    @ApiOperation("获取文件修订/废止申请单详情")
    @GetMapping("/{id}")
    public ResponseEntity<Xdfeizhi> getXdfeizhiById(@PathVariable Long id) {
        return ResponseEntity.ok(xdfeizhiService.getXdfeizhiWithRevisions(id));
    }

    @ApiOperation("新增or修改文件修订/废止申请单")
    @PostMapping("/saveOrUpdate")
    public ResponseEntity<Boolean> saveXdfeizhi(@RequestBody Xdfeizhi xdfeizhi) {
        return ResponseEntity.ok(xdfeizhiService.saveXdfeizhiWithRevisions(xdfeizhi));
    }

    @ApiOperation("修改文件修订/废止申请单")
    @PutMapping("/{id}")
    public ResponseEntity<Boolean> updateXdfeizhi(@PathVariable Long id, @RequestBody Xdfeizhi xdfeizhi) {
        xdfeizhi.setId(id);
        return ResponseEntity.ok(xdfeizhiService.updateXdfeizhiWithRevisions(xdfeizhi));
    }

    @ApiOperation("删除文件修订/废止申请单")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> removeXdfeizhi(@PathVariable Long id) {
        return ResponseEntity.ok(xdfeizhiService.removeXdfeizhiWithRevisions(id));
    }
}